package 每日一题;

import java.util.HashMap;

public class CheckInclusion {
    public boolean checkInclusion(String s1, String s2) {
        int[] cur1=new int[26];
        int[] cur2=new int[26];
        int m=s1.length();
        int n=s2.length();

        for (char c:s1.toCharArray()){
            ++cur1[c-'a'];
        }
        for (int j=0;j<m;j++){
            cur2[s2.charAt(j)-'a']++;
        }
        if(check(cur1,cur2)){
            return true;
        }

        for (int j=m;j<n;j++){
            cur2[s2.charAt(j)-'a']++;
            cur2[s2.charAt(j-m)-'a']--;
            if(check(cur1,cur2)){
                return true;
            }

        }
        return false;
    }

    boolean check(int[] nums,int[] nums2){
        for (int i=0;i<26;i++){
            if(nums[i]!=nums2[i]){
                return false;
            }
        }
        return true;
    }
}
